$(document).ready(function () {

    //判断浏览器信息
    var boswer = minimum();
    if (!boswer) {
        window.oddBoswer = true;
    }

    function minimum() {
        var agent = navigator.userAgent.toLowerCase();
        var regStr_ie = /msie [\d.]+;/gi;
        var regStr_ie_rv = /rv:[\d.]+/gi;
        var regStr_ff = /firefox\/[\d.]+/gi
        var regStr_chrome = /chrome\/[\d.]+/gi;
        var regStr_saf = /safari\/[\d.]+/gi;
        var version = 0;

        //firefox
        if (agent.indexOf("firefox") > 0) {
            version = (agent.match(regStr_ff) + "").replace(/[^0-9.]/ig, "");
            window.userBoswer = "firefox";
            return (version >= "51");
        }

        //IE
        if (agent.indexOf("msie") > 0) {
            version = (agent.match(regStr_ie) + "").replace(/[^0-9.]/ig, "");
            window.userBoswer = "ie";
            if (Number(version) >= "11") {
                return Number(version);
            } else if (Number(version) >= "9" && Number(version) < "11") {
                window.browserVertion = "10";
                return Number(version);
            }

        }
        if (agent.indexOf("rv") > 0) {
            version = (agent.match(regStr_ie_rv) + "").replace(/[^0-9.]/ig, "");
            window.userBoswer = "ie";
            return (version >= "11");
        }
        //Chrome
        if (agent.indexOf("chrome") > 0) {
            version = (agent.match(regStr_chrome) + "").replace(/[^0-9.]/ig, "");
            window.userBoswer = "chrome";
            return (version >= "53");
        }
        //Safari
        if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {
            version = (agent.match(regStr_saf) + "").replace(/[^0-9.]/ig, "");
            window.userBoswer = "safari";
            return (version >= "5.34.57.2");
        }

    }

    if (window.userBoswer && (window.userBoswer === "ie")) {
        $(".nav-menu-submenu-container").css({marginTop: "-25px", display: "none"});
        $("#qq").find(".nav-menu-submenu-container").css({marginLeft: "-2%"});
        $("#email").find(".nav-menu-submenu-container").css({marginLeft: "-4.5%"});
    }

    //头部导航栏事件
    $(window).scroll(function () {
        $("#nav-bg").stop().animate({
            opacity: (jQuery(window).scrollTop() / 1000) > 0.75 ? 0.75 : (jQuery(window).scrollTop() / 1000)
        });
    });
    $(".nav-menu-title").hover(
        function () {
            $(this).siblings(".nav-menu-underline").stop().animate({
                opacity: 1,
                width: "100%"
            });
            if (window.userBoswer && (window.userBoswer === "ie")) {
                $(this).siblings(".nav-menu-submenu-container").css({display: "inline"});
            }
            $(this).siblings(".nav-menu-submenu-container").stop().animate({
                opacity: 1
            });
            if ($(this).parent().attr('id') === "qq") {
                $(this).children("a").children("img").attr("src", "images/icon/qq-active.png");
            } else if ($(this).parent().attr('id') === "wechat") {
                $(this).children("img").attr("src", "images/icon/wechat-active.png");
            } else if ($(this).parent().attr('id') === "email") {
                $(this).children("a").children("img").attr("src", "images/icon/email-active.png");
            } else if ($(this).parent().attr('id') === "blog") {
                $(this).children("a").children("img").attr("src", "images/icon/weibo_hover.png");
            }
        },
        function () {
            $(this).siblings(".nav-menu-underline").stop().animate({
                opacity: 0,
                width: 0
            });
            if ($(this).parent().attr('id') === "qq") {
                $(this).children("a").children("img").attr("src", "images/icon/qq.png");
            } else if ($(this).parent().attr('id') === "wechat") {
                $(this).children("img").attr("src", "images/icon/wechat.png");
            } else if ($(this).parent().attr('id') === "email") {
                $(this).children("a").children("img").attr("src", "images/icon/email.png");
                $("#email").children(".nav-menu-submenu-container").css({opacity: 0});
            } else if ($(this).parent().attr('id') === "blog") {
                $(this).children("a").children("img").attr("src", "images/icon/weibo.png");
                $("#blog").children(".nav-menu-submenu-container").css({opacity: 0});
            }
        }
    );
    // $(".nav-menu").hover(
    //     function () {
    //     },
    //     function () {
    //         $(this).find(".nav-menu-submenu-container").animate({
    //             opacity: 0
    //         }, 100);
    //         if (window.userBoswer && (window.userBoswer === "ie")) {
    //             $(this).siblings(".nav-menu-submenu-container").css({display: "none"});
    //         }
    //     }
    // );

    $(".nav-menu").click(
        function () {
            $(this).addClass("on").siblings(".nav-menu").removeClass("on")
        }
    );
    //头部鼠标事件



    //定义页面跳转
    window.forwardTo = function (url, param) {
        if (param) {
            window.location.href = url + "?" + param;
        } else {
            window.location.href = url
        }
    };

    //获取url参数
    window.getQueryStringValue = function (name) {
        if (!window._cachedQueryString) {
            var cache = {};
            var params = window.location.search.substr(1).split('&');
            for (var i = 0; i < params.length; i++) {
                var param = params[i];
                var equalIndex = param.indexOf('=');
                var paramName = equalIndex < 0 ? param : param.substring(0, equalIndex);
                paramName = decodeURIComponent(paramName);
                var paramValue = equalIndex < 0 ? '' : param.substr(equalIndex + 1);
                paramValue = decodeURIComponent(paramValue);
                cache[paramName] = paramValue;
            }
            window._cachedQueryString = cache;
        }
        return window._cachedQueryString[name];
    }

    //图片加载时间-轮询
    var isLoad = false;
    var t_img;
    window.isImageLoad = function (callback) {
        $(".base-image").each(function () {
            if (this.height == 0) {
                isLoad = false;
                return false;
            }
        });
        if (isLoad) {
            clearTimeout(t_img);
            callback();
        } else {
            isLoad = true;
            t_img = setTimeout(function () {
                isImageLoad(callback); // 递归扫描
            }, 500);
        }
    }
});